package com.sim.util;

import java.util.List;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.sim.domain.PsychologicalHealthType;
import com.sim.domain.SocietyType;
import com.sim.domain.SubsidizeType;
import com.sim.service.PhtService;
import com.sim.service.SocietyTypeService;
import com.sim.service.SubsidizeTypeService;

public class InitListener implements ServletContextListener {


	@Override
	public void contextInitialized(ServletContextEvent sce) {
		// 获取容器与相关的Service对象
		ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
		SocietyTypeService societyTypeService = (SocietyTypeService) ac.getBean("societyTypeServiceImpl");
        //准备数据：societyTypeList
		List<SocietyType> societyTypeList = societyTypeService.findAll();
		sce.getServletContext().setAttribute("societyTypeList", societyTypeList);
		System.out.println("------------> 已准备数据societyTypeList <------------"+societyTypeList);
		
		
		SubsidizeTypeService subsidizeTypeService = (SubsidizeTypeService) ac.getBean("subsidizeTypeServiceImpl");
		 //准备数据：subsidizeTypeList
		List<SubsidizeType> subsidizeTypeList = subsidizeTypeService.findAll();
		sce.getServletContext().setAttribute("subsidizeTypeList", subsidizeTypeList);
		System.out.println("------------> 已准备数据subsidizeTypeList <------------"+subsidizeTypeList);
		// 准备数据：topPrivilegeList
		
		
		PhtService phtService = (PhtService) ac.getBean("phtServiceImpl");
		 //准备数据：subsidizeTypeList
		List<PsychologicalHealthType> phtList = phtService.findAll();
		sce.getServletContext().setAttribute("phtList", phtList);
		System.out.println("------------> 已准备数据phtList <------------"+phtList);
		// 准备数据：topPrivilegeList

	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		// TODO Auto-generated method stub
		
	}

}
